home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / nansisrc.arc / NANSI_I.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-05-22  |  3.0 KB  |  112 lines

  1.     page    66, 132
  2. ;------ nansi_i.asm ----------------------------------------------
  3. ; Contains code only needed at initialization time.
  4. ; (C) 1986 Daniel Kegel
  5. ; May be distributed for educational and personal use only
  6. ;-----------------------------------------------------------------
  7.  
  8.     include nansi_d.asm        ; definitions
  9.  
  10.     ; to nansi.asm
  11.     public    dosfn0
  12.  
  13.     ; from nansi.asm
  14.     extrn    break_handler:near
  15.     extrn    int_29:near
  16.     if    takeBIOS
  17.     extrn    new_vid_bios:near
  18.     extrn    old_vid_bios:dword
  19.     endif
  20.     extrn    req_ptr:dword
  21.     extrn    xlate_tab_ptr:word
  22.  
  23.     ; from nansi_p.asm
  24.     extrn    param_buffer:word    ; adr of first byte free for params
  25.     extrn    param_end:word        ; adr of last byte used for params
  26.     extrn    redef_end:word        ; adr of last used byte for redefs
  27.  
  28.  
  29. code    segment byte public 'CODE'
  30.     assume    cs:code, ds:code
  31.  
  32. ;-------- dos function # 0 : init driver ---------------------
  33. ; Initializes device driver interrupts and buffers, then
  34. ; passes ending address of the device driver to DOS.
  35. ; Since this code is only used once, the buffer can be set up on top
  36. ; of it to save RAM.
  37.  
  38. dosfn0    proc    near
  39.     ; Install BIOS keyboard break handler.
  40.     xor    ax, ax
  41.     mov    ds, ax
  42.     mov    bx, 6Ch
  43.     mov    word ptr [BX],offset break_handler
  44.     mov    [BX+02], cs
  45.     ; Install INT 29 quick putchar.
  46.     mov    bx, 0a4h
  47.     mov    word ptr [bx], offset int_29
  48.     mov    [bx+2], cs
  49.     if    takeBIOS
  50.     ; Install INT 10h video bios replacement.
  51.     mov    bx, 40h
  52.     mov    ax, [bx]
  53.     mov    word ptr cs:old_vid_bios, ax
  54.     mov    ax, [bx+2]
  55.     mov    word ptr cs:old_vid_bios[2], ax
  56.     mov    word ptr [bx], offset new_vid_bios
  57.     mov    word ptr [bx+2], cs
  58.     endif
  59.  
  60.     push    cs
  61.     pop    ds
  62.     push    cs
  63.     pop    es            ; es=cs so we can use stosb
  64.     cld                ; make sure stosb increments di
  65.  
  66.     ; Calculate addresses of start and end of parameter/redef buffer.
  67.     ; The buffer occupies the same area of memory as this code!
  68.     ; ANSI parameters are accumulated at the lower end, and
  69.     ; keyboard redefinitions are stored at the upper end; the variable
  70.     ; param_end is the last byte used by params (changes as redefs added);
  71.     ; redef_end is the last word used by redefinitions.
  72.     mov    di, offset dosfn0
  73.     mov    param_buffer, di
  74.     add    di, 512
  75.     mov    param_end, di    ; addr of last byte in free area
  76.     inc    di
  77.  
  78.     ; Build the default redefinition table:
  79.     ;    control-printscreen -> control-P
  80.     ; (Must be careful not to write over ourselves here!)
  81.     mov    al, 16        ; control P
  82.     stosb
  83.     mov    ax, 7200h    ; control-printscreen
  84.     stosw
  85.     mov    ax, 1        ; length field
  86.     mov    redef_end, di    ; address of last used word in table
  87.     stosw
  88.  
  89.     ; Build a 1:1 output character translation table.
  90.     ; It is 256 bytes long, starts just after the param/redef buffer,
  91.     ; and is the last thing in the initialized device driver.
  92.     mov    xlate_tab_ptr, di
  93.     xor    ax, ax
  94. init_loop:
  95.     stosb
  96.     inc    al
  97.     jnz    init_loop
  98.  
  99.     xor    ax, ax
  100.     ; Return ending address of this device driver.
  101.     ; Status is in AX.
  102.     lds    si, req_ptr
  103.     mov    word ptr [si+0Eh], di
  104.     mov    [si+10h], cs
  105.     ; Return exit status in ax.
  106.     ret
  107.  
  108. dosfn0    endp
  109.  
  110. code    ends
  111.     end                ; of nansi_i.asm
  112.